-- -*- haskell -*-

-- Get ready for debugging.
let __nc_debug__ _ = return ":set -fbreak-on-error"
:def nc:debug __nc_debug__

-- A more friendly version of ":forward" and ":back": takes a "how
-- far" argument, and does ":history" and ":list" after moving.  Note
-- that ":nc:move 0" degenerates to ":history" and ":list" with no
-- movement.
:{
let __nc_move__ s = do
    let n = if length s > 0 then read s else 0
        cmd = if n > 0 then ":forward" else ":back"
    return $ unlines
           $ replicate (abs n) cmd
           ++ [ ":! echo ; echo 'HISTORY:'" ,  ":history"
              , ":! echo ; echo 'SOURCE:'" ,   ":list"
              , ":! echo ; echo 'BINDINGS:'" , ":show bindings"
              ]
:}
:def nc:move __nc_move__

:def nc:where (const $ return ":nc:move 0")

-- Step 'n' (default one) times and then show context.
--
-- Might be more useful to make something like
--
--   :nc:do d x y n ==> x ... x (n times, default d) y
--
-- then e.g. ':nc:step', ':nc:steplocal', ':nc:forward',
-- ':nc:backward' are all useful instances.
:{
let __nc_step__ s = do
    let n = if length s > 0 then read s else 1
    return . unlines $ replicate n ":step" ++ [ ":nc:where" ]
:}
:def nc:step __nc_step__

-- Warnings.

-- It's bad to set -W by default since :unset -W does not work :P

-- :set -W

-- The -fno-warn-unused-binds turns off warns about unused and
-- unexported top-level defs, and unused local defs, but not unused
-- pattern bindings.  Those can be disabled with
-- -fno-warn-unused-matches.

-- :set -fno-warn-unused-binds

-- Save more history:
-- http://stackoverflow.com/questions/20133443/how-to-configure-amount-of-command-history-saved-by-ghci

-- The prompt is defined else where; use `nc:ghci` to load it.
-- :script ~/v/conf/dot.ghc/non-prompt.ghci
:!echo '\033[5;31mThe fancy prompt is defined separately; use `nc:ghci` to load it.\033[0m'
